package com.gl.spring.restTemplate;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class RestTemplateController {
	private Logger logger = Logger.getLogger(RestTemplateController.class);

	@RequestMapping(value = "/template", method = { RequestMethod.GET,
			RequestMethod.POST })
	public @ResponseBody
	Object test(@RequestBody String param) throws Exception {
//		ObjectMapper mapper = new ObjectMapper();
//		JsonNode rootNode = mapper.readTree(param.toString());
//		String id = rootNode.path("id").asText();
//		String name = rootNode.path("name").asText();
//		System.out.println("XML:[--" + param + "," + id + "," + name + "--]");
		System.out.println("--param:" + param);
		return "jajajjaja";
	}
	
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/templateMap", method = { RequestMethod.GET,
			RequestMethod.POST })
	public @ResponseBody Object templateMap(@RequestBody Map<String, Object> requestMap) throws Exception {
		String resourceId = (String)(requestMap.get("resourceId"));
		System.out.println("--requestMap:" + requestMap.toString());
		System.out.println("--resourceId:" + resourceId);
		return "templateMap";
	}
	
	@RequestMapping(value = "/templateList", method = { RequestMethod.GET, RequestMethod.POST })
	public @ResponseBody Object templateList(@RequestBody List<String> objectIds) throws Exception {
		System.out.println("--objectIds:" + objectIds);
		System.out.println("--objectIds Array:" + objectIds.toArray());
		return "templateList";
	}

	@RequestMapping(value = "/material/{type}/{count}", method = {RequestMethod.GET, RequestMethod.POST })
	public @ResponseBody
	Object materialStatics(@PathVariable("type") String type, @PathVariable("count") int count)
			throws Exception {
		System.out.println("Test:[--param:" + ",type:" + type
				+ ",count:" + count + "--]");
		return "jajajjaja";
	}

}